package com.ruoyi.channel.controller;

import com.ruoyi.channel.domain.bo.TChannelDataStaffBo;
import com.ruoyi.channel.domain.vo.TChannelDataStaffVo;
import com.ruoyi.channel.service.ITChannelDataStaffService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 渠道数据管理员业务员配置
 *
 * @author ruoyi
 * @date 2023-11-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/channel/channelDataStaff")
public class TChannelDataStaffController extends BaseController {

    private final ITChannelDataStaffService iTChannelDataStaffService;

    /**
     * 查询渠道数据管理员业务员配置列表
     */
    //@SaCheckPermission("channel:channelDataStaff:list")
    @GetMapping("/list")
    public TableDataInfo<TChannelDataStaffVo> list(TChannelDataStaffBo bo, PageQuery pageQuery) {
        return iTChannelDataStaffService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出渠道数据管理员业务员配置列表
     */
    //@SaCheckPermission("channel:channelDataStaff:export")
    @Log(title = "渠道数据管理员业务员配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TChannelDataStaffBo bo, HttpServletResponse response) {
        List<TChannelDataStaffVo> list = iTChannelDataStaffService.queryList(bo);
        ExcelUtil.exportExcel(list, "渠道数据管理员业务员配置", TChannelDataStaffVo.class, response);
    }

    /**
     * 获取渠道数据管理员业务员配置详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("channel:channelDataStaff:query")
    @GetMapping("/{id}")
    public R<TChannelDataStaffVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iTChannelDataStaffService.queryById(id));
    }

    /**
     * 新增渠道数据管理员业务员配置
     */
    //@SaCheckPermission("channel:channelDataStaff:add")
    @Log(title = "渠道数据管理员业务员配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TChannelDataStaffBo bo) {
        return toAjax(iTChannelDataStaffService.insertByBo(bo));
    }

    /**
     * 修改渠道数据管理员业务员配置
     */
    //@SaCheckPermission("channel:channelDataStaff:edit")
    @Log(title = "渠道数据管理员业务员配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TChannelDataStaffBo bo) {
        return toAjax(iTChannelDataStaffService.updateByBo(bo));
    }

    /**
     * 删除渠道数据管理员业务员配置
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("channel:channelDataStaff:remove")
    @Log(title = "渠道数据管理员业务员配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iTChannelDataStaffService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
